package ${controllerPackage};

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import com.alibaba.fastjson.JSON;
import ${entityPackage}.${className};
import ${commonPackage}.entity.Result;
import ${commonPackage}.enums.FailureCodeEnum;
import ${commonPackage}.enums.OpTypeEnum;
import ${servicePackage}.${className}Service;
import ${controllerPackage}.base.BaseController;

 /**
 * 描述：</b>${codeName}控制器实现<br>
 * @author：系统生成
 * @version:1.0
 */
@Controller
public class ${className}Controller extends BaseController {

	@SuppressWarnings("unused")
	private final static Logger logger= LoggerFactory.getLogger(${className}Controller.class);
	
	@Resource
	private ${className}Service ${lowerName}Service;
	
	/**
	 * 描述:获取${codeName}列表页
	 * @return
	 */
	@RequestMapping("get${className}ListPage.do")
    public String get${className}ListPage(Model model) {
        return "/biz/${className?upper_case}/query${className}List";
    }
    
    /**
	 * 描述:异步查询${codeName}列表请求
	 * @param query 查询资源菜单列表条件信息
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "asynQuery${className}List.do", produces = "text/html;charset=UTF-8")
	public String query${className}List(${className} query) {
		return this.paginationResultToJson(${lowerName}Service.query${className}ByPage(query));
	}
    
	/**
	 * 描述:异步保存${codeName}列表请求
	 * <p>创建人：jrzhangwei , 2014年12月20日 下午1:37:52</p>
	 * @param ${lowerName} 需要保存的${codeName}
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@ResponseBody
	@RequestMapping(value = "asynSave${className}.do", produces = "text/html;charset=UTF-8")
	public String asynSave${className}(${className} ${lowerName},@RequestParam("saveType") String opType) {
		Result<${className}> result = null;
		if(OpTypeEnum.ADD.getCode().equals(opType)){
			result = ${lowerName}Service.insert${className}(${lowerName});
		}else if(OpTypeEnum.UPDATE.getCode().equals(opType)){
			result = ${lowerName}Service.update${className}ByPrimaryKey(${lowerName});
		}else{
			result = Result.getFailureResult(FailureCodeEnum.INVALID_OPTYPE_PARAM.getCode(), "操作类型参数【"+opType+"】非法！");
		}
		return this.resultToJson(result);
	}
	
	/**
	 * 
	 * 描述:异步删除指定的${codeName}请求
	 * @param ${lowerName}Ids 需删除的${codeName}ID列表
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@ResponseBody
	@RequestMapping(value = "asynDelete${className}.do", produces = "text/html;charset=UTF-8")
	public String delete${className}(@RequestParam String ${lowerName}Ids) {
		List<String> ${lowerName}IdList = JSON.parseArray(${lowerName}Ids, String.class);
		Result<${className}> result = Result.getSuccessResult();
		for(String ${lowerName}Id : ${lowerName}IdList){
			if(result.isSuccess()){
				//result = ${lowerName}Service.deleteByPrimaryKey(${lowerName}Id);
			}else{
				break;
			}
		}
		return this.resultToJson(result);
	}
	
	/*user customize code start*/
${userCustomCode}
	/*user customize code end*/
}
